import $service from '../../service'
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    startDate: '',
    endDate: '',
    value: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    bindDateChange(e) {
      let {type} = e.currentTarget.dataset
      let {value} = e.detail
      if (type == 'start') {
        if (this.data.endDate) {
          if ($service.timeFormat(value) > $service.timeFormat(this.data.endDate)) {
              $service.showToast('结束时间不可小于开始时间');
              return
          }
          this.data.startDate = value
        } else {
          this.data.startDate = value
        }
      } else { 
        if (this.data.startDate) {
          if ($service.timeFormat(this.data.startDate) > $service.timeFormat(value)) {
                $service.showToast('结束时间不可小于开始时间');
                return
              }
          }
        this.data.endDate = value
      }
      this.setData({
        startDate: this.data.startDate,
        endDate: this.data.endDate
      })
      this.triggerEvent('changeDate', {
        startDate: this.data.startDate,
        endDate: this.data.endDate
      })
    },
    toDetail(e) {
      this.triggerEvent('toDetail', e.currentTarget.dataset.id)
    }
  }
})
